home *** CD-ROM | disk | FTP | other *** search
- ; ctags.cmd, for MicroEmacs (c) Daniel Lawrence
- ;
- ; 01 Jun 89 S.D. Maley No longer compatible w/ versions of MicroEmacs
- ; prior to 3.10 .
- ; Added next-tag, because a tag may occur more
- ; than once in the tags file (Could NOT macro-to-key
- ; next-tag M-FN^V).
- ; Added locality preference, so that a tag
- ; that points to the file we came from is given
- ; precedence over one in another file.
- ; MAGIC mode can NOT be used to search for the
- ; "regular expression" in the tagged file. Aside from
- ; the anchor characters "^" and "$", the rest of the
- ; expression is the LITERAL string ctags found in the
- ; file. None of the special characters recognized in
- ; MAGIC mode are escaped by the version of ctags in use.
- ; Thus:
- ; "^#define BCONSTAT 1 /* return status */$"
- ;
- ; will fail, because "/*" matches "/", NOT the literal
- ; "/*" actually in the line.
- ;
- ; 26 Apr 89 S.D. Maley Isolate tagged_file & tagged_regex better.
- ; add-mode exact or magic caused macro termination
- ; under HPUX 5.2 . !force them.
- ; 25 Apr 89 S.D. Maley Handle more than whitespace in front of
- ; the tag we want to look for.
- ; 22 Apr 89 S.D. Maley Add %ctags_exact. If user sets it TRUE
- ; before invoking the to-tag macro, the search
- ; will be case-sensitive. Useful in C, but not
- ; for most Fortran implementations.
- ; 19 Apr 89 S.D. Maley Initial implementation.
- ;
- ; Macros to make use of Unix-like ctags tag file.
- ; Assumes the existence of a file called "tags"
- ; (or whatever %tags_file is currently set to)
- ; which can be created using the "ctags" utility.
- ; If this file doesn't exist, the tags file is reported "Not found".
- ; The format of each line of the tags file must be:
- ;
- ; tagword filename ?^pattern$?
- ;
- ; This is the normal output produced by the Unix utility "ctags".
- ;
- ; For those unfamiliar with tagging, it is a form of hypertext.
- ; If you create a tags file for all your C source files you can locate
- ; the file and line where a given function is declared when you're in
- ; the editor, even if that function is declared in a different
- ; source file from the one you are editing. Tagging will move you
- ; to that line in that file.
- ;
- ; To use these macros, you can call "to-tag" directly as a command,
- ; or invoke it with the key combination M-<PgDn>. Invoked directly,
- ; it will ask you to enter a tag. Give the name of the function you
- ; are searching for (case sensitivity will depend on the current emacs
- ; setting). If invoked with M-<PgDn>, the word where the cursor is
- ; positioned will be used as the tag to search for.
-
- write-message "[Loading ctags macros]"
-
- set %ctag ""
- set %ctag_ "" ;-- for next-tag
- set %ctags_exact FALSE ;-- set TRUE for case-sensitive searches
- set %ct_from_f "" ;-- for find-next-tag
- set %tag_lvl 0
- set %tags_file "tags" ;-- this can be reset from within Emacs
-
- store-procedure find-next-tag
- !force search-forward %ctag
- !if ¬ $status
- write-message &cat "Tag Not found: " %ctag
- execute-procedure tag-out
- !return
- !endif
-
- ;-- Give precedence to a file that matches the one we came from
- execute-procedure tagged-file-name
- set %curline_ $curline
- set %curcol_ $curcol
- !while ¬ &sequ &upper %tagged_file %ct_from_f
- !force search-forward %ctag
- !if ¬ $status
- goto-line %curline_
- set $curcol %curcol_
- !break
- !endif
- execute-procedure tagged-file-name
- !endwhile ;-- looking for a local tag
- ;-- isolate the regular expression
- 3 forward-character ;-- skip the leading whitespace & delimiters
- set %tagged_regex #$cbufname
- set %tagged_regex &left %tagged_regex &sub &len %tagged_regex 2
-
- ;-- get on down
-
- !force view-file %tagged_file
- !if ¬ $status
- execute-procedure tag-out
- write-message &cat "File Not found: " %tagged_file
- !return
- !endif
- execute-procedure set-bmodes
- end-of-file ;-- in case we've been this way before
- ;-- search until we match at the beginning of a line
- !while $status
- !force search-reverse %tagged_regex
- !if &less $curcol 1
- !break
- !endif
- !endwhile
- !if $status
- write-message "<Esc><PgUp> to pop back"
- !else
- execute-procedure tag-out
- write-message &cat "Tag Declaration Not found:~n" %tagged_regex
- write-message "~ntags file should be re-generated with ctags"
- !return
- !endif
- !endm ;-- find-next-tag
-
-
- store-procedure in-word
- !if &equ $curchar 95 ; underscore
- set %in-word TRUE
- !else
- !if &and &less 64 $curchar &less $curchar 91 ; (A-Z)
- set %in-word TRUE
- !else
- !if &and &less 96 $curchar &less $curchar 123 ; (a-z)
- set %in-word TRUE
- !else
- set %in-word FALSE
- !endif
- !endif
- !endif
- !endm
-
- store-procedure next-tag
- execute-procedure tag-dn-level
- execute-procedure view-tags
- !if ¬ %status
- !return
- !endif
- set %ctag %ctag_
- execute-procedure find-next-tag
- set %ctag ""
- !endm
-
- store-procedure set-bmodes
- !if %ctags_exact ; case-sensitive search
- !force add-mode exact
- !endif
- !if &sequ %tags_buff $cbufname
- !force add-mode magic ; enable regular expression search
- !else
- !force delete-mode magic ; dis-allow
- !endif
- !endm
-
- store-procedure tag-dn-level
- ;-- push down a level
- set %tag_lvl &add %tag_lvl 1
- set &ind &cat "%tag_b" %tag_lvl $cbufname
- set &ind &cat "%tag_c" %tag_lvl $curcol
- set &ind &cat "%tag_l" %tag_lvl $curline
- set &ind &cat "%tag_m" %tag_lvl $cmode
- !endm
-
- store-procedure tagged-file-name
- ;-- isolate the filename in the tags buffer (trailed by whitespace)
- ;-- assuming we are positioned at the end of the tag
- set %tagged_file ""
- forward-character ;-- skip the leading whitespace
- !while &equ 0 &sindex " ~t" &chr $curchar
- set %tagged_file &cat %tagged_file &chr $curchar
- forward-character
- !endwhile
- !endm
-
- ; to-tag
- ;
- ; Looks in tags file for given tag, gets the filename and search
- ; pattern to use in locating the tag, opens the given file and
- ; searches for the pattern. If the tag isn't found, reports an
- ; error. There is no error checking in this macro for a valid
- ; function name (tag).
-
- store-procedure to-tag
- ;-- remember what file we came from for find-next-tag
- set %ct_from_f &upper $cbufname
- execute-procedure tag-dn-level ;-- remember where we were
- ;-- find out what we're looking for
- !if &equ &len %ctag 0
- set %prompt "tag: "
- set %ctag @%prompt
- !else
- ;-- align cursor to beginning of tag
- execute-procedure in-word
- !while %in-word
- !force backward-character ;-- back up till we're not in a word
- !if ¬ $status
- !break ;-- apparently clears $status
- !endif
- execute-procedure in-word
- !endwhile ; in-word
- !if ¬ &and &equ $curcol 0 &equ $curline 1 ;-- beginning-of-file
- !force forward-character
- !endif
- ;-- isolate the tag
- set %ctag_ "^" ;-- tie to beginning-of-line
- execute-procedure in-word
- !while %in-word
- set %ctag_ &cat %ctag_ &chr $curchar
- !force forward-character
- !if ¬ $status
- !break ; a while
- !endif
- execute-procedure in-word
- !endwhile
- !endif
- set %ctag %ctag_
-
- ;-- See if it's in the tags file
-
- execute-procedure view-tags
- !if ¬ %status
- !return
- !endif
- execute-procedure set-bmodes
- beginning-of-file ;-- in case we've been this way before
- execute-procedure find-next-tag
- set %ctag ""
- !endm
-
- ; tag-out
- ;
- ; puts us back where we were before invoking tag
- ;
- store-procedure tag-out
- !if &less 0 %tag_lvl ;-- "&gre %tag_lvl 1" doesn't work
- ;-- pop out a tag level
-
- select-buffer &ind &cat "%tag_b" %tag_lvl
- set $cmode &ind &cat "%tag_m" %tag_lvl
- goto-line &ind &cat "%tag_l" %tag_lvl
- set $curcol &ind &cat "%tag_c" %tag_lvl
- set %tag_lvl &sub %tag_lvl 1
- update-screen
- !endif
- set %ctag ""
- !endm
-
- store-procedure view-tags
- !force view-file %tags_file
- !if $status
- set %tags_buff $cbufname
- set %status TRUE
- !else
- execute-procedure tag-out
- write-message &cat "File Not found: " %tags_file
- set %status FALSE ;-- we can NOT set $status
- !endif
- !endm
-
- store-procedure key-to-tag
- set %ctag find
- execute-procedure to-tag
- !endm
-
- store-procedure key-tag-out
- clear-message-line
- execute-procedure tag-out
- !endm
-
- macro-to-key key-to-tag M-FNV ;-- <Esc><PgDn>
- macro-to-key next-tag M-FN> ;-- <Esc><End> (could NOT: <Esc><Ctrl><PgDn>)
- macro-to-key key-tag-out M-FNZ ;-- <Esc><PgUp>
-